import xlrd
import xlwt

user_data = xlrd.open_workbook("人员列表库.xls")
user_data_table = user_data.sheets()[0]                    #通过索引顺序获取

workbook = xlwt.Workbook(encoding= 'ascii')

# 创建新的sheet表
new_sheet = workbook.add_sheet("人员列表")

name = "王昊"
line_num =0
new_sheet.write(line_num,0, "RYXM")
new_sheet.write(line_num,1, "RYSFZH")
new_sheet.write(line_num,2, "RYSJH")
new_sheet.write(line_num,3, "CPH")
new_sheet.write(line_num,4, "RYSSDW")
new_sheet.write(line_num,5, "RYXWJZD")
new_sheet.write(line_num,6, "RYBZ")
line_num =1
new_sheet.write(line_num,0, "姓名")
new_sheet.write(line_num,1, "身份证号")
new_sheet.write(line_num,2, "手机号")
new_sheet.write(line_num,3, "车牌号(非大客车)")
new_sheet.write(line_num,4, "工作单位")
new_sheet.write(line_num,5, "居住地")
new_sheet.write(line_num,6, "备注")
line_num = 2
for i in range(2,user_data_table.nrows):
    name_t = user_data_table.cell_value(i,0)
    if(name_t == name ):
        print("find")
        _id = user_data_table.cell_value(i,1)
        _phone = user_data_table.cell_value(i,2)
        _work_address = user_data_table.cell_value(i,4)
        _home_address = user_data_table.cell_value(i,5)
        _note = user_data_table.cell_value(i,6)
        print(_id)
        print(_phone)
        print(_work_address)
        print(_home_address)
        print(_note)
         # 往表格写入内容
        new_sheet.write(line_num,0, name_t)
        new_sheet.write(line_num,1, _id)
        new_sheet.write(line_num,2, _phone)

        new_sheet.write(line_num,4, _work_address)
        new_sheet.write(line_num,5, _home_address)
        new_sheet.write(line_num,6, _note)
        line_num = line_num + 1
        


    print(name_t)
workbook.save("A报备人员.xls")
    
